<?php
namespace app\admin\controller;
use think\Db;
/**
 * 商家
 * Class Member
 */
class ShopController extends BaseController {

	public function index($is_on_sale='',$name=''){
		$where=[];
		if($name){
		$where['name']=['like','%'.$name.'%'];
		}
		$this->assign('name',$name);
		if($is_on_sale){
			$where['is_on_sale']=$is_on_sale;
		}
		$this->assign('is_on_sale',$is_on_sale);
		$list=db("shop")->where($where)->paginate(2);
		$this->assign('list',$list);
		return $this->fetch();
	}
	public function update($id){
		if ($this->request->isPost()) {
			$data=get_query()['query'];;
			$res=db('shop')->update($data);
			if($res){
				$this->success('更新成功',url("index"));
				
			}else{
				$this->success('更新失败');	
			}
			
		}
		 $this->assign('shop',db('shop')->find($id));
		 return $this->fetch();
	}
	public function add(){
		if ($this->request->isPost()) {
			$data=get_query()['query'];;
			$data['add_time']=now_time();
			$res=db('shop')->insert($data);
			if($res){
				$this->success('添加成功',url("index"));
				
			}else{
				$this->success('添加失败');	
			}
			
		}
		 
		return $this->fetch();
	}
	
	
}
